package com.example.android_20190529_01;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.os.Handler;
import android.os.Message;
import java.util.Timer;
import java.util.TimerTask;

public class FrameLayoutActivity extends AppCompatActivity {
    Button btn_back;
    private ImageView image;
    private int[] imgs={R.mipmap.img01,R.mipmap.img02,R.mipmap.img03,R.mipmap.img04,R.mipmap.img05};
//    private static  Handler handler;
    Handler  handler;
    Timer timer=new Timer();
    private int n=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.uc3);
//        返回主菜单
        btn_back=findViewById(R.id.btn_back);
        btn_back.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                startActivity(new Intent(FrameLayoutActivity.this,MainActivity.class));
            }
        });
        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                    if (n>=imgs.length){
                        n=0;
                    }
                    image.setImageResource(imgs[n++]);
            }
        };
        TimerTask task =new TimerTask() {
            @Override
            public void run() {
                Message msg = new Message();
                handler.sendMessage(msg);
            }
        };
        image=(ImageView) findViewById(R.id.img1);
        timer.schedule(task,200,500);
    }
}
